package com.taichuan.selfcheck.ui.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import com.taichuan.selfcheck.R;
import com.taichuan.selfcheck.entity.file.FileInfo;
import com.taichuan.selfcheck.mvp.presenter.EmptyPresenter;
import com.taichuan.selfcheck.mvp.viewinterface.EmptyInterface;
import com.taichuan.selfcheck.ui.fragment.base.AppBaseFragment;
import java.io.File;
import butterknife.BindView;

/**
 * 该类主要用于
 *
 * @author CamelLuo
 * @version 2021/12/25
 */
public class PhotoViewFragment extends AppBaseFragment<EmptyInterface, EmptyPresenter> implements EmptyInterface {
    private static final String TAG = PhotoViewFragment.class.getSimpleName();

    private static final String PARAM_KEY_FILE_INFO = "open_file_info";

    @BindView(R.id.photoView_photoView)
    PhotoView photoView;

    private FileInfo fileInfo;

    @Override
    protected void getBundleValues(Bundle bundle) {
        if (bundle != null) {
            fileInfo = bundle.getParcelable(PARAM_KEY_FILE_INFO);
        }
    }

    /**
     * 定义一个方法用于供外部组件启动Activity时传入携带参数
     *
     * @param fileInfo 文件信息
     */
    public static Bundle setBundleValue(FileInfo fileInfo) {
        Bundle bundle = new Bundle();
        bundle.putParcelable(PARAM_KEY_FILE_INFO, fileInfo);
        return bundle;
    }

    @Override
    protected int setContentViewId() {
        return R.layout.fragment_photo_view;
    }

    @Override
    protected void initView(View view, Bundle bundle) {
        if (fileInfo != null){
            Log.e(TAG,"加载的图片路径为：  " + fileInfo.getFilePath());

            //加载图片
            File imageFile = new File(fileInfo.getFilePath());
            Glide.with(this)
                    .load(imageFile)
                    .into(photoView);
        }
    }

    @Override
    protected EmptyPresenter createPresenter() {
        return new EmptyPresenter();
    }

    @Override
    protected boolean isAllowAutoFinishFragment() {
        return false;
    }

    @Override
    public void doOnAutoFinishFragment() {
        operateFragmentManagerBack();
    }
}
